package io.gitee.loulan_yxq.owner.mybatisPlus.test.config.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.executor.keygen.NoKeyGenerator;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

import java.util.HashMap;

/*********************************************************
 ** 测试查询方法
 ** <br><br>
 ** Date: Created in 2022/6/24 11:25
 ** @author loulan
 ** @version 0.0.0
 *********************************************************/
public class MySelect extends AbstractMethod {

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        //String sql = "insert into %s %s values %s";
        //StringBuilder fieldSql = new StringBuilder();
        //fieldSql.append(tableInfo.getKeyColumn()).append(",");
        //StringBuilder valueSql = new StringBuilder();
        //valueSql.append("#{").append(tableInfo.getKeyProperty()).append("},");
        //tableInfo.getFieldList().forEach(x->{
        //    fieldSql.append(x.getColumn()).append(",");
        //    valueSql.append("#{").append(x.getProperty()).append("},");
        //});
        //fieldSql.delete(fieldSql.length()-1, fieldSql.length());
        //fieldSql.insert(0, "(");
        //fieldSql.append(")");
        //valueSql.insert(0, "(");
        //valueSql.delete(valueSql.length()-1, valueSql.length());
        //valueSql.append(")");
        //SqlSource sqlSource = languageDriver.createSqlSource(configuration, String.format(sql, tableInfo.getTableName(), fieldSql.toString(), valueSql.toString()), modelClass);
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, "select * from dg_client", modelClass);

        return this.addSelectMappedStatementForOther(mapperClass, "mySelect", sqlSource, HashMap.class);
    }

}
